#pragma warning(disable : 4996)
#include"list.h"
void Init(List* head)
{
	assert(head);
	int* arr = (int*)malloc(sizeof(int) * 4);
	if (arr == NULL)
	{
		perror("malloc fail");
	}
	else
	{
		head->arr = arr;
	}
	head->capacity = 4;
	head->count = 0;
	
}

void ListDestory(List* head)
{
	free(head->arr);
	//head->arr = NULL;
	head->capacity = 0;
	head->count = 0;
}

void Capacity(List* head)
{
	int* tail = realloc(head->arr, sizeof(int) * head->capacity * 2);
	if (tail == NULL)
	{
		perror("relloc fail");
	}
	else
	{
		head->arr = tail;
	}
	head->capacity *= 2;
}

void Add(List* head,int x)
{
	assert(head);
	if (head->count == head->capacity)
	{
		Capacity(head);
	}
	head->arr[head->count] = x;
	head->count++;
}

int Pop(List*head)
{
	if (head->count == 0)
	{
		assert(head->count!= 0);
	}
	head->count--;
	return head->arr[head->count];

}